package com.lxy.controller;


import cn.hutool.core.bean.BeanUtil;
import com.lxy.bean.Customer;
import com.lxy.common.bean.PageBean;
import com.lxy.common.bean.ResultBean;
import com.lxy.common.controller.BaseController;
import com.lxy.common.group.ISave;
import com.lxy.common.group.V;
import com.lxy.query.CustomerQuery;
import com.lxy.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
@Api(tags = "客户管理")
public class CustomerController extends BaseController {

    @Autowired
    CustomerService customerService;


    @ApiOperation("查询客户")
    @GetMapping("/customer")
    public ResultBean get(String id) {
        Customer customer = customerService.get(id);
        return  success("客户信息",customer);
    }

    @ApiOperation("保存客户")
    @PostMapping("/customer")
    public ResultBean save(@Validated(ISave.class) @RequestBody  Customer customer, BindingResult result) {
        V.validate(result);
        return success("");

    }


    @ApiOperation("客户列表")
    @PostMapping("/customer/list")
    public ResultBean<PageBean<List<Customer>>> query(@RequestBody CustomerQuery query) {

//        PageBean pageBean = customerService.query(query);
        PageBean pageBean = customerService.queryByMap(BeanUtil.beanToMap(query));

        return success("客户列表",pageBean);

    }

}
